from django.conf.urls.defaults import *
from django.contrib import admin
from django.conf import settings
from photologue.models import Gallery,Photo
from django.views.generic.list_detail import object_list
from django.views.generic.simple import direct_to_template
from tagging.views import tagged_object_list

admin.autodiscover()

# Override admin interface for 3rd party Django apps without touching their code
# Must come after autodiscover!
import mesawa.admin_overrides


front_config = {
    # Get latest gallery
    'queryset': Gallery.objects.filter(
                    is_public=True).order_by('-date_added')[:1],
    'template_name': 'front.html',
}
photo_tags_cfg = {
    'queryset_or_model':Photo.objects.filter(is_public=True), 
    'paginate_by':20, 
    'allow_empty':True,
    'template_name':'photologue/photo_list.html',
}

urlpatterns = patterns('',
    (r'^admin/(.*)', admin.site.root),
    (r'^$', object_list, front_config),
    (r'^about/$', 
     direct_to_template, 
     dict(template="about.html"),),
    url(r'^photo/tags/$', 
        direct_to_template,
        dict(template='tags_list.html'),
        name='photo_tags_list',),
    url(r'^photo/tags/(?P<tag>[^/]+)/$',
        tagged_object_list, 
        photo_tags_cfg,
        name='photo_tags_detail'),
    (r'', include('photologue.urls')),
)

if settings.DEBUG:
    urlpatterns += patterns('',
        (
            r'^media/(?P<path>.*)$',
            'django.views.static.serve',
            {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}
        ),
    )
